package com.xbongbong.pro.enums.businessrule.enums;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.AssembleEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CompetitorEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.ContractOutstockEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.InstockEnum;
import com.xbongbong.saas.enums.business.InventoryEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.ProductionInstockEnum;
import com.xbongbong.saas.enums.business.ProductionMaterielOutstockEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.PurchaseInstockEnum;
import com.xbongbong.saas.enums.business.PurchaseInvoiceEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.RefundInstockEnum;
import com.xbongbong.saas.enums.business.ReturnedMaterielInstockEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseOutstockEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.SupplierCommunicateEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.business.TransferEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.business.WorkOrderEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 业务规则-操作
 * @references: https://xbb.yuque.com/lfwuxq/vsf9sv/ctyt57
 * @author xingxing.xiao
 * @date 2020/06/10 16:17
 */
@Getter
public enum RuleOperatorBusinessFieldEnum {

    /**
     * 客户管理
     *       NAME_SHORT -> text_2 -> 客户简称      ADDRESS -> address_1 -> 客户地址          SEX -> text_23 -> 性别
     *       QQ -> text_24 -> QQ                  WE_CHRT -> text_25 -> 微信               GENRE -> text_3 -> 客户类型                IS_INDIVIDUAL -> text_5 -> 客户性质     SCALE -> text_6 -> 客户分级
     *       INDUSTRY -> text_7 -> 客户行业        SOURCE -> text_9 -> 客户来源             WEBSITE -> text_10 -> 客户官网            INSTRUCTION -> text_11 -> 客户简介       COUNTRY -> text_8 -> 国家
     *       HOBBIES -> text_26 -> 爱好           IMAGE -> file_1 -> 图片                  MEMO -> text_13 -> 备注
     */
    CUSTOMER_MANAGEMENT(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), new String[]{CustomerManagementEnum.NAME_SHORT.getAttr(), CustomerManagementEnum.ADDRESS.getAttr(), CustomerManagementEnum.SEX.getAttr(),
            CustomerManagementEnum.QQ.getAttr(), CustomerManagementEnum.WE_CHRT.getAttr(), CustomerManagementEnum.GENRE.getAttr(), CustomerManagementEnum.IS_INDIVIDUAL.getAttr(), CustomerManagementEnum.SCALE.getAttr(),
            CustomerManagementEnum.INDUSTRY.getAttr(), CustomerManagementEnum.SOURCE.getAttr(), CustomerManagementEnum.WEBSITE.getAttr(), CustomerManagementEnum.INSTRUCTION.getAttr(), CustomerManagementEnum.COUNTRY.getAttr(),
            CustomerManagementEnum.HOBBIES.getAttr(), CustomerManagementEnum.IMAGE.getAttr(), CustomerManagementEnum.MEMO.getAttr()}),
    /**
     * 联系人
     *       EMAIL -> text_6 -> 邮箱           QQ -> text_7 -> QQ           ADDRESS -> address_1 -> 地址
     *       ZIP_CODE -> text_8 -> 邮编        SEX -> text_9 -> 性别        BIRTHDAY -> text_14 -> 生日(不支持)            HOBBIES -> text_11 -> 爱好                MEMO -> text_12 -> 备注       DEPARTMENT -> text_3 -> 部门
     *       POSITION -> text_4 -> 职务        LEVEL -> text_5 -> 级别      IMPORTANT_DEGREE -> num_1 -> 重要程度(☆)      RELATIONSHIP -> text_10 -> 决策关系
     */
    CONTACT(XbbRefTypeEnum.CONTACT.getCode(), new String[]{ContactEnum.EMAIL.getAttr(), ContactEnum.QQ.getAttr(), ContactEnum.ADDRESS.getAttr(),
            ContactEnum.ZIP_CODE.getAttr(), ContactEnum.SEX.getAttr(), ContactEnum.HOBBIES.getAttr(), ContactEnum.MEMO.getAttr(), ContactEnum.DEPARTMENT.getAttr(),
            ContactEnum.POSITION.getAttr(), ContactEnum.LEVEL.getAttr(), ContactEnum.RELATIONSHIP.getAttr()}),
    /**
     * 跟进记录
     *       TYPE -> text_4 -> 跟进方式       IMAGES -> file_1 -> 图片
     */
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), new String[]{CustomerCommunicateEnum.TYPE.getAttr(), CustomerCommunicateEnum.IMAGES.getAttr()}),
    /**
     * 销售机会
     *       COMPETITOR -> text_9 -> 竞争对手
     */
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), new String[]{SalesOpportunityEnum.COMPETITOR.getAttr()}),
    /**
     * 报价单
     *       QUOTATION_PERSON -> text_5 -> 报价人
     */
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), new String[]{QuotationEnum.QUOTATION_PERSON.getAttr()}),
    /**
     * 合同订单
     *       SIGN_PERSON -> text_8 -> 签订人         SIGN_TIME -> date_1 -> 签订日期
     *       TYPE -> text_7 -> 合同类型              PAY_METHOD -> text_9 -> 付款方式      EXPRESS_STATUS -> text_10 -> 发货状态      EXPRESS_NAME -> text_11 -> 物流公司      EXPRESS_NO -> text_12 -> 物流编号
     */
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), new String[]{ContractEnum.SIGN_PERSON.getAttr(), ContractEnum.SIGN_TIME.getAttr(),
            ContractEnum.TYPE.getAttr(), ContractEnum.PAY_METHOD.getAttr(), ContractEnum.EXPRESS_STATUS.getAttr(), ContractEnum.EXPRESS_NAME.getAttr(), ContractEnum.EXPRESS_NO.getAttr()}),
    /**
     * 退货退款
     *       SIGN_USER -> text_13 -> 签订人          SIGN_DATE -> date_1 -> 签订日期
     *       REFUND_REASON -> text_4 -> 退货原因     MEMO -> text_5 -> 退货备注
     */
    REFUND(XbbRefTypeEnum.REFUND.getCode(), new String[]{RefundEnum.SIGN_USER.getAttr(), RefundEnum.SIGN_DATE.getAttr(),
            RefundEnum.REFUND_REASON.getAttr(), RefundEnum.MEMO.getAttr()}),
    /**
     * 销项发票
     *       INVOICE_NUMBER -> text_2 -> 发票号码      INVOICE_TYPE -> text_6 -> 发票类型     MEMO -> text_7 -> 备注
     */
    INVOICE(XbbRefTypeEnum.INVOICE.getCode(), new String[]{InvoiceEnum.INVOICE_NUMBER.getAttr(), InvoiceEnum.INVOICE_TYPE.getAttr(), InvoiceEnum.MEMO.getAttr()}),
    /**
     * 进项发票
     *       INVOICE_NUMBER -> text_1 -> 发票号码     INVOICE_TYPE -> text_7 -> 发票类型     MEMO -> text_8 -> 备注
     */
    PURCHASE_INVOICE(XbbRefTypeEnum.PURCHASE_INVOICE.getCode(), new String[]{PurchaseInvoiceEnum.INVOICE_NUMBER.getAttr(), PurchaseInvoiceEnum.INVOICE_TYPE.getAttr(), PurchaseInvoiceEnum.MEMO.getAttr()}),
    /**
     * 回款单
     *     PAY_METHOD -> text_3 -> 支付方式     MEMO -> text_7 -> 备注
     */
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), new String[]{PaymentSheetEnum.PAY_METHOD.getAttr(), PaymentSheetEnum.MEMO.getAttr()}),
    /**
     * 付款单
     *     PAY_TYPE -> text_2 -> 支付方式       MEMO -> text_8 -> 备注
     */
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET.getCode(), new String[]{PaySheetEnum.PAY_TYPE.getAttr(), PaySheetEnum.MEMO.getAttr()}),
    /**
     * 供应商
     *       SHORT_NAME -> text_2 -> 供应商简称               THUMBNAIL -> file_1 -> 供应商图片       MEMO -> text_8 -> 备注
     *       REGISTERED_CAPITAL -> num_6 -> 注册资本         COUNTRY -> text_5 -> 国家               ADDRESS -> address_1 -> 地址      WEBSITE -> text_6 -> 网站         ANNUAL_OUTPUT -> num_7 -> 年产值
     */
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), new String[]{SupplierEnum.SHORT_NAME.getAttr(), SupplierEnum.THUMBNAIL.getAttr(), SupplierEnum.MEMO.getAttr(),
            SupplierEnum.REGISTERED_CAPITAL.getAttr(), SupplierEnum.COUNTRY.getAttr(), SupplierEnum.ADDRESS.getAttr(), SupplierEnum.WEBSITE.getAttr(), SupplierEnum.ANNUAL_OUTPUT.getAttr()}),
    /**
     * 供应商联系人
     *       ADDRESS -> address_1 -> 地址      EMAIL -> text_6 -> 邮箱        QQ -> text_7 -> QQ
     *       SEX -> text_8 -> 性别             MEMO -> text_9 -> 备注         DEPARTMENT -> text_3 -> 部门      POSITION -> text_4 -> 职务     LEVEL -> text_5 -> 级别
     */
    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), new String[]{SupplierContactEnum.ADDRESS.getAttr(), SupplierContactEnum.EMAIL.getAttr(), SupplierContactEnum.QQ.getAttr(),
            SupplierContactEnum.SEX.getAttr(), SupplierContactEnum.MEMO.getAttr(), SupplierContactEnum.DEPARTMENT.getAttr(), SupplierContactEnum.POSITION.getAttr(), SupplierContactEnum.LEVEL.getAttr()}),
    /**
     * 供应商跟进记录
     *       TYPE -> text_4 -> 跟进方式     IMAGES -> file_1 -> 图片
     */
    SUPPLIER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), new String[]{SupplierCommunicateEnum.TYPE.getAttr(), SupplierCommunicateEnum.IMAGES.getAttr()}),
    /**
     * 采购合同
     *       PAY_METHOD -> text_4 -> 支付方式     STATUS -> text_5 -> 状态    SIGNER_ID -> text_6 -> 签订人      SIGN_TIME -> date_1 -> 签订日期      MEMO -> text_8 -> 备注
     */
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), new String[]{PurchaseEnum.PAY_METHOD.getAttr(), PurchaseEnum.STATUS.getAttr(), PurchaseEnum.SIGNER_ID.getAttr(), PurchaseEnum.SIGN_TIME.getAttr(), PurchaseEnum.MEMO.getAttr()}),
    /**
     * 采购退货单
     *       MEMO -> text_4 -> 备注
     */
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), new String[]{ReturnedPurchaseEnum.MEMO.getAttr()}),
    /**
     * BOM 清单
     *       NAME -> text_2 -> BOM名称         MEMO -> text_7 -> 备注
     */
    BOM_BILL(XbbRefTypeEnum.BOM_BILL.getCode(), new String[]{BomBillEnum.NAME.getAttr(), BomBillEnum.MEMO.getAttr()}),
    /**
     * 生产单
     *      PLAN_TIME -> date_1 -> 计划完成日期      MEMO -> text_9 -> 备注
     */
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), new String[]{ProductionOrderEnum.PLAN_TIME.getAttr(), ProductionOrderEnum.MEMO.getAttr()}),
    /**
     * 装配出入库单
     *      MEMO -> text_3 -> 备注
     */
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), new String[]{AssembleEnum.MEMO.getAttr()}),
    /**
     * 盘点单
     *      MEMO -> text_5 -> 备注
     */
    INVENTORY(XbbRefTypeEnum.INVENTORY.getCode(), new String[]{InventoryEnum.MEMO.getAttr()}),
    /**
     * 调拨单
     *      MEMO -> text_3 -> 备注
     */
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), new String[]{TransferEnum.MEMO.getAttr()}),
    /**
     * 采购入库单
     *      MEMO -> text_7 -> 备注
     */
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), new String[]{PurchaseInstockEnum.MEMO.getAttr()}),
    /**
     * 销售退货入库单
     *      MEMO -> text_7 -> 备注
     */
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), new String[]{RefundInstockEnum.MEMO.getAttr()}),
    /**
     * 其他入库单
     *      MEMO -> text_7 -> 备注
     */
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), new String[]{InstockEnum.MEMO.getAttr()}),
    /**
     * 生产入库单
     *      MEMO -> text_7 -> 备注
     */
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), new String[]{ProductionInstockEnum.MEMO.getAttr()}),
    /**
     * 生产退料单
     *      MEMO -> text_7 -> 备注
     */
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), new String[]{ReturnedMaterielInstockEnum.MEMO.getAttr()}),
    /**
     * 销售出库单
     *      MEMO -> text_6 -> 备注
     */
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), new String[]{ContractOutstockEnum.MEMO.getAttr()}),
    /**
     * 采购退货出库单
     *      MEMO -> text_6 -> 备注
     */
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), new String[]{ReturnedPurchaseOutstockEnum.MEMO.getAttr()}),
    /**
     * 其他出库单
     *      MEMO -> text_6 -> 备注
     */
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), new String[]{OutstockEnum.MEMO.getAttr()}),
    /**
     * 生产领料单
     *      MEMO -> text_6 -> 备注
     */
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), new String[]{ProductionMaterielOutstockEnum.MEMO.getAttr()}),
    /**
     * 工单出库-砍掉
     */
    /*WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), new String[]{WorkOrderOutstockEnum.SHEET_NO.getAttr(), WorkOrderOutstockEnum.TIME.getAttr(), WorkOrderOutstockEnum.REF_ID.getAttr(), WorkOrderOutstockEnum.WAREHOUSE_ID.getAttr(), WorkOrderOutstockEnum.PRODUCT_INFO.getAttr(), WorkOrderOutstockEnum.PRODUCT.getAttr(),
            WorkOrderOutstockEnum.LINK_CUSTOMER.getAttr(), WorkOrderOutstockEnum.LINK_CONTACT.getAttr(), WorkOrderOutstockEnum.CUSTOMER_PHONE.getAttr(), WorkOrderOutstockEnum.CUSTOMER_ADDRESS.getAttr(), WorkOrderOutstockEnum.EXPRESS_NAME.getAttr(), WorkOrderOutstockEnum.EXPRESS_NO.getAttr(),
            WorkOrderOutstockEnum.MANAGER_ID.getAttr(), WorkOrderOutstockEnum.MEMO.getAttr(), WorkOrderOutstockEnum.CREATOR_ID.getAttr(), WorkOrderOutstockEnum.ADD_TIME.getAttr(), WorkOrderOutstockEnum.UPDATE_TIME.getAttr()}),*/
    /**
     * 仓库
     *      ADDRESS -> address_1 -> 地址      MANAGER_DEP_ID -> array_1 -> 负责部门   MEMO -> text_5 -> 备注
     */
    WAREHOUSE(XbbRefTypeEnum.WAREHOUSE.getCode(), new String[]{WarehouseEnum.ADDRESS.getAttr(), WarehouseEnum.MANAGER_DEP_ID.getAttr(), WarehouseEnum.MEMO.getAttr()}),

    /**
     * 线索
     *      CONTACT -> text_2 -> 联系人      ADDRESS -> address_1 -> 地址   CLUE_SOURCE -> text_4 -> 线索来源   IMAGE -> file_1 -> 图片    MEMO -> text_9 -> 备注
     */
    CLUE(XbbRefTypeEnum.CLUE.getCode(), new String[]{ClueEnum.CONTACT.getAttr(), ClueEnum.ADDRESS.getAttr(), ClueEnum.CLUE_SOURCE.getAttr(), ClueEnum.IMAGE.getAttr(), ClueEnum.MEMO.getAttr()}),

    /**
     * 市场活动
     *      GENRE -> text_2 -> 活动类型      ESTIMATE_COST -> num_1 -> 预计成本   REAL_COST -> num_2 -> 实际成本   ESTIMATE_INCOME -> num_3 -> 预计收入    REAL_INCOME -> num_4 -> 实际收入
     *      STATUS -> text_3 -> 活动状态      CAPTION -> text_4 -> 活动说明   ADDRESS -> address_1 -> 地点   MEMO -> text_5 -> 备注
     */
    MARKET_ACTIVITY(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), new String[]{MarketActivityEnum.GENRE.getAttr(), MarketActivityEnum.ESTIMATE_COST.getAttr(), MarketActivityEnum.REAL_COST.getAttr(),
            MarketActivityEnum.ESTIMATE_INCOME.getAttr(), MarketActivityEnum.REAL_INCOME.getAttr(), MarketActivityEnum.STATUS.getAttr(), MarketActivityEnum.CAPTION.getAttr(), MarketActivityEnum.ADDRESS.getAttr(),
            MarketActivityEnum.MEMO.getAttr()}),
    /**
     * 工单 - businessType：2301
     *
     */
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), new String[]{WorkOrderEnum.MEMO.getAttr(), WorkOrderEnum.EMERGENCY_LEVEL.getAttr()}),

    /**
     * 竞争对手
     */
    COMPETITOR(XbbRefTypeEnum.COMPETITOR.getCode(),new String[]{CompetitorEnum.SCALE.getAttr(),CompetitorEnum.INSTRUCTION.getAttr(),CompetitorEnum.ADDRESS.getAttr(),CompetitorEnum.WEBSITE.getAttr()}),


    /**
     * 回执单
     */
    RECEIPT_ORDER(XbbRefTypeEnum.RECEIPT_ORDER.getCode(),new String[]{"text_3"}),

    ;

    /**
     * 业务类型
     */
    private int code;

    /**
     * 字段数组
     */
    private String[] attrArray;

    RuleOperatorBusinessFieldEnum(int code, String[] attrArray) {
        this.code = code;
        this.attrArray = attrArray;
    }

    public static JSONArray getAttrsByCode (Integer code) {
        JSONArray array = new JSONArray();
        for (RuleOperatorBusinessFieldEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                String[] attrArray = cacheCode.getAttrArray();
                array = JSONArray.parseArray(JSON.toJSONString(attrArray));
                return array;
            }
        }
        return array;
    }

}
